/******************************************************************************
 * Copyright (C) 2017 Chengdu Dlhd information industry co. LTD.
 * All Rights Reserved.
 * 本软件为成都顶联互动信息产业有限公司开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、复制、修改或发布本软件.
 *****************************************************************************/
package net.dgg.dggcloud.service.iboss.service.common;

import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.entity.user.User;
import net.dgg.dggcloud.service.iboss.entity.ScProFlowOperating;
import net.dgg.dggcloud.service.iboss.entity.ScProOrder;
import net.dgg.dggcloud.service.iboss.service.sc.WaitAllocationService;
import net.dgg.dggcloud.service.iboss.utils.DataWrap;
import net.dgg.dggcloud.service.jrcrm.service.cms.CustomerRecordService;
import net.dgg.dggcloud.service.jrcrm.service.cms.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class ChargeBackService extends BaseService {
    @Autowired
    private CustomerRecordService customerRecordService;
    @Resource
    protected MessageService messageService;
    @Autowired
    private WaitAllocationService waitAllocationService;

    public ScProOrder queryScproorder(Long id) {
        ScProOrder scProOrder = repository.get(ScProOrder.class, id);
        return scProOrder;
    }

    public User queryAuditUser(Long id) {
        User user = repository.get(User.class, id);
        return user;
    }

    public void saveChargeBack(ScProOrder scProOrder, ScProFlowOperating scProFlowOperating, Map recordMap) {
        scProFlowOperating.setId(this.keyWorker.nextId());
        scProOrder.setFlowLatestOperationId(scProFlowOperating.getId());
        DataWrap.saveWrap(scProFlowOperating); //封装公共字段数据
        scProFlowOperating.setReturnOrAbandonTime(scProFlowOperating.getCreateTime()); //申请退单时间
        repository.saveOrUpdate(scProOrder);
        repository.save(scProFlowOperating);
        waitAllocationService.updateUserSetting(scProOrder, "1");//减1
        customerRecordService.saveCustomerRecord(recordMap);//写入crm

    }
}
